package com.mebs.model;

import static org.hibernate.proxy.HibernateProxyHelper.getClassWithoutInitializingProxy;

import javax.persistence.*;

/**
 * Created by Sergey Prasolov, sap@jensentechnologies.com
 * Date: Mar 10, 2006, 6:40:19 PM
 */
@Entity()
@Table(name = "REQ_TYPE",
    uniqueConstraints = {@UniqueConstraint(columnNames={"Discriminator", "Name"})}
)
@Inheritance(strategy = InheritanceType.SINGLE_TABLE)
@DiscriminatorColumn(name = "Discriminator", discriminatorType = DiscriminatorType.STRING, length = 15)
public abstract class SimpleType {
    @Id
    @GeneratedValue(strategy = GenerationType.AUTO)
    @Column(name = "Id")
    private Long id;

    @Column(name = "Name", nullable = false, length = 250)
    private String name;

    @Column(name = "Description", nullable = true, length = 1024)
    private String description;


    public SimpleType()
    {
    }

    /**
     * **********************
     * Getters-setters
     * ***********************
     */

    public Long getId()
    {
        return id;
    }

    public void setId(Long id)
    {
        this.id = id;
    }

    public String getName()
    {
        return name;
    }

    public void setName(String name)
    {
        this.name = name;
    }

    public String getDescription()
    {
        return description;
    }

    public void setDescription(String description)
    {
        this.description = description;
    }

    @Override
    public String toString()
    {
        return this.name;
    }

    @Override
    public int hashCode()
    {
        if (id == null) return super.hashCode();
        return id.hashCode();
    }

    @Override
    public boolean equals(Object o)
    {
        if (o == null) return false;
        if (this == o) return true;
        if (id == null) return false;
        if (getClassWithoutInitializingProxy(o) != getClassWithoutInitializingProxy(this) &&
            ! getClassWithoutInitializingProxy(o).isAssignableFrom(SimpleType.class))
            return false;
        final SimpleType that = (SimpleType) o;
        return id.equals(that.getId());
    }


}
